#include <stdio.h>
#include <stdlib.h>

#define SHM_QUEUE_IMPLEMENTATION
#define SHM_NOTIFY_IMPLEMENTATION


#if _WIN32
#include "shm_queue_win.h"
#include "shm_notify_win.h"
#else
#include "shm_queue_linux.h"
#include "shm_notify_linux.h"
#endif

int main() {
  shm_notify_t wnotify;
  shm_queue_t wqueue;
  shm_queue_options_t options;
  options.elem_count = 128;
  options.elem_size = 1024;
  options.mode = SHM_QUEUE_MODE_WRITE;
  options.name = "test";
  int rslt = shm_queue_open(&wqueue, &options);
  printf("shm_queue_open ret:%d\n", rslt);


  rslt = shm_notify_open(&wnotify, "TestNotify");
  printf("shm_notify_open ret:%d\n", rslt);


  while (1) {
    static const char str[] = "123456789012345678901234567890";
    int rslt = shm_queue_write(&wqueue, (void*)str, rand() % sizeof(str));
    if (rslt < 0) {
      printf("shm_queue_write  error ret:%d\n", rslt);
    } else {
      shm_notify_send(&wnotify);
    }

#ifdef _WIN32
    Sleep(100);
#else
    usleep(100000);
#endif
  }

  printf("finish\n");
  shm_queue_close(&wqueue);
  return 0;
}
